#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include"game.h"
void InitBoard(char Board[ROW][COL], int row, int col)
{
	int i = 0;
	for (i = 0; i < row; i++)
	{
		int j = 0;
		for (j = 0; j < col; j++)
		{
			Board[i][j] = ' ';
		}
	}
}

void DisplayBoard(char Board[ROW][COL], int row, int col)
{
	int i = 0;
	//打印数据和|
	for (i = 0; i < row; i++)
	{
		int j = 0;
		for (j = 0; j < col; j++)
		{
			printf(" %c ", Board[i][j]);
			if (j < col - 1)
				printf("|");
		}
		printf("\n");

		//打印分割线和|
		if (i < row - 1)
		{
			int j = 0;
			for (j = 0; j < col; j++)
			{
				printf("---");
				if (j < col - 1)
				{
					printf("|");
				}
			}
			printf("\n");
		}
	}
}
void PlayerMove(char Board[ROW][COL], int row, int col)
{

	int x = 0;
	int y = 0;

	while (1)
	{
		printf("请输入落子下标，两个数字用空格隔开\n");
		scanf("%d %d", &x, &y);
		//合法输入坐标
		if (x >= 1 && x <= row && y <= col && y >= 1)
		{
			//坐标处为空格，可以输入
			if (Board[x - 1][y - 1] == ' ')
			{
				Board[x - 1][y - 1] = '*';
				break;
			}
			else
			{
				printf("坐标已经被占用，请重新输入\n");
			}
		}
		else
		{
			printf("非法输入，请重新输入\n");
		}
	}
}
void ComputerMove(char Board[ROW][COL], int row, int col)
{
	int x = 0;
	int y = 0;
	printf("电脑下棋\n");
	while (1)
	{
		x = rand() % row;
		y = rand() % col;
		if (Board[x][y] == ' ')
		{
			Board[x][y] = '#';
			break;
		}
	}
}
IsFull(char Board[ROW][COL], int row, int col)
{
	int i = 0;
	for (i = 0; i < row; i++)
	{
		int j = 0;
		for (j = 0; j < col; j++)
		{
			if (Board[i][j] == ' ')
				return 0;
		}
	}
	return 1;



}
IsWin(char Board[ROW][COL], int row, int col)
{
	//行的赢法
	int i = 0;
	for (i = 0; i < row; i++)
	{
		if (Board[i][0] == Board[i][1] && Board[i][2] == Board[i][1] && Board[i][0] != ' ')
		{
			return Board[i][1];
		}
	}
	//列的赢法
	int j = 0;
	for (i = 0; i < row; i++)
	{
		if (Board[0][j] == Board[1][j] && Board[2][j] == Board[1][j] && Board[0][j] != ' ')
		{
			return Board[1][j];
		}
	}
	//对角线赢法
	if (Board[0][0] == Board[1][1] && Board[1][1] == Board[2][2] && Board[0][0] != ' ')
		return Board[0][0];
	if (Board[0][2] == Board[1][1] && Board[1][1] == Board[2][0] && Board[0][2] != ' ')
		return Board[0][0];
	//平局
	if (IsFull(Board, row, col) == 1)
	{
		return 'Q';
	}


	return 'C';
}